package com.ifonly.activerecord.sql.handlers;

import com.ifonly.activerecord.sql.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author <a href="mailto:ifonlymaster@163.com">ifonly</a>
 * @version 1.0 2015-12-25 16:49
 * @since JDK 1.6
 */
public abstract class AbstractListHandler<T> extends ResultSetHandler<List<T>> {

    @Override
    public List<T> handle(ResultSet rs) throws SQLException {
        List<T> result = new ArrayList<T>();
        while (rs.next()) {
            result.add(handleResultSet(rs));
        }
        return result;
    }

    public abstract T handleResultSet(ResultSet rs) throws SQLException;

}
